package demo3;

import java.util.concurrent.TimeUnit;

public class Text01 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("hello thread...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        // 启动之前看一下线程的状态
        System.out.println("启动之前：" + thread.getState());
        // 启动线程
        thread.start();
        // 查看状态前等待一会
        TimeUnit.MILLISECONDS.sleep(500);
        // 启动之后线程的状态
        System.out.println("启动之后：" + thread.getState());
        // 等待线程执行完成
        thread.join();
        // 线程结束之后查看状态
        System.out.println("结束之后：" + thread.getState());
    }
}
